#ifndef RobustHashTable_First
#define RobustHashTable_First
#ifdef __GNUG__
#pragma interface
#endif

#include "HashTable.h"

class Set;

//---- RobustHashTable ---------------------------------------------------------

struct TabEntry {
	int prv, nxt;
	inline void Set(int aPrv, int aNxt)
		{ prv= aPrv; nxt= aNxt; };
};

class RobustHashTable : public HashTable {
public:
	MetaDef(RobustHashTable);
	RobustHashTable(Set *aClient, int initCapacity,
				pEqualFunc eq, pHashFunc hash, int *size= 0);
	~RobustHashTable();
	void Empty(int newCapacity= cContainerInitCap);

	//---- iterator support
	void *AtNextIndex(int &idx);
	void *AtPrevIndex(int &idx);
	int GetInitialIndex();
protected:
	void Init();
	//---- table primitives
	void *KeyAt(int i);
	void SetKeyAt(void *obj, int i);
	void NullAt(int i);
	void Swap(int i, int j);

	//--- algorithm
	void RemoveSlot(int slot);
	void Rehash(int newCapacity);
	HashTable *MakeNew(int initCapacity);
	void Assign(HashTable *ht);
protected:
	Object **tab;
	TabEntry *seq;
	Set *client;
};

#endif


